package com.example.smartcitydemo.viewModel.SubwayViewModel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.switchMap
import com.example.smartcity_jscs.network.ResultStates.Resource
import com.example.smartcitydemo.bean.SubWayStartDetail
import com.example.smartcitydemo.ext.getLiveData
import com.example.smartcitydemo.repo.subway.SubwayRepo
import kotlinx.serialization.Serializable

/**
 * @PACKAGE_NAME: com.example.smartcitydemo.viewModel.SubwayViewModel
 * @NAME: Caleb.F
 * @DATE: 2021/11/16 9:55
 * @Email: 1919796283@qq.com
 */

@Serializable
data class SubWayDetailTransform(
    val lineName: String,
    val lineIds: String
)

class SubWaySharedViewModel : ViewModel() {
    private val mutableSubWayData: MutableLiveData<SubWayDetailTransform> = MutableLiveData()
    val subWayDetail: LiveData<Resource<SubWayStartDetail>> = mutableSubWayData.switchMap {
        getLiveData { SubwayRepo.getStationDetailInfo(it) }
    }

    fun getSubWayDetail(subWayDetailTransform: SubWayDetailTransform) {
        mutableSubWayData.value = subWayDetailTransform
    }
}